<template>
	<view class="home">
		<!-- 轮播区域 -->
		<swiper :circular="circular" class="swiper" :indicator-color="color" :indicator-active-color="coloract"
		 :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval2" :duration="duration2">
			<swiper-item v-for="item in bannerlist" :key="item.id">
				<image class="bannerimage" :src="item.pic" mode=""></image>
			</swiper-item>
		</swiper>
		<!-- banner下面分类区域 -->
		<view class="sort">
			<view @click="tosortinfo(item.id,item.name)" class="item" v-for="item in sortlist" :key="item.id">
				<image :src="item.icon" mode=""></image>
				<view class="text">
					{{item.name}}
				</view>
			</view>
		</view>
		<!-- 通知区域 -->
		<view class="notice">
			<view class="notice-left">
				<image src="../../static/images/icons/notice.png" mode=""></image>
				<view class="text">
					限时活动:
				</view>
			</view>
			<swiper class="swiper" :vertical="circular" :circular="circular" :autoplay="autoplay" :interval="interval" :duration="duration">
				<swiper-item @click="togoodsinfo(item.productId)" class="item" v-for="item in activitylist" :key='item.productId'>
					<view class="goodsname">
						{{item.name}}
					</view>
					<view class="goodsprice">
						<view class="oldprice">{{item.price}}元</view>
						<view class="newprice">现价: {{item.promotionPrice}}元</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- 热门推荐 -->
		<view class="area-title">
			热门推荐
		</view>
		<swiper class="swiper-hot" :easing-function="easing" :acceleration="autoplay" :disable-touch="autoplay" :circular="circular"
		 :display-multiple-items="num" :autoplay="autoplay" :interval="interval3" :duration="duration3">
			<swiper-item @click="togoodsinfo(item.id)" class="item" v-for="item in hotlist" :key="item.id">
				<image class="bannerimage" :src="item.pic" mode=""></image>
				<view class="name">
					{{item.name}}
				</view>
			</swiper-item>
		</swiper>

		<!-- 新品推荐 -->
		<view class="area-title">
			新品推荐
		</view>
		<view class="newgoods">
			<view @click="togoodsinfo(item.id)" class="item" v-for="item in newlist">
				<image :src="item.pic" mode=""></image>
				<view class="goodsinfo">
					<view class="name">
						{{item.name}}
					</view>
					<view class="price">
						价格: {{item.price}}
					</view>
				</view>
			</view>
		</view>

		<!-- 新品推荐 -->
		<view class="area-title">
			猜你喜欢
		</view>
		<view class="like">
			<view @click="togoodsinfo(item.id)" class="item" v-for="item in lejuNewlist" :key='item.id'>
				<image :src="item.pic" mode=""></image>
				<view class="title">
					{{item.name}}
				</view>
				<view class="brandprice">
					<view class="price">
						￥: {{item.price}}元
					</view>
					<view class="brand">
						乐居
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		adsCountInc,
		bannerAds,
		categorys,
		hotList,
		latestProducts,
		lejuLatestProducts,
		recommendList,
		saleMostProducts
	} from "../../api/home/home.js"
	export default {
		data() {
			return {
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				interval1: 1000,
				interval3: 3000,
				duration3: 3000,
				duration: 1000,
				duration2: 1000,
				circular: true,
				interval2: 3000,
				easing: 'easeOutCubic',
				num: 3,
				color: '#767674',
				coloract: "#D8D8D8",

				bannerlist: "",
				sortlist: "",
				activitylist: "",
				hotlist: "",
				newlist: '',
				lejuNewlist: '',
			}
		},
		methods: {

			togoodsinfo(id) {
				console.log(id);
				uni.navigateTo({
					url: `./goodsinfo/goodsinfo?id=${id}`
				})
			},
			// 到分类详细页面
			tosortinfo(ids, name) {
				console.log(ids);
				uni.navigateTo({
					url: `../sort/sortinfo/sortinfo?id=${ids}&name=${name}`
				})
			},
			init() {
				var _this = this
				//获取轮播图片
				bannerAds().then(res => {
					console.log(res)
					this.bannerlist = res.data.items
				})
				//获取轮播下面的分类
				categorys("1308336521604599809").then(res => {
					console.log(res.data.category)
					this.sortlist = res.data.category.children
				})
				//限时活动
				uni.request({
					url: "http://leju.bufan.cloud/lejuClient/home/recommendList",
					method: 'GET',
					success(res) {
						console.log(res.data.data.items);
						_this.activitylist = res.data.data.items
					}
				})
				//热门推荐
				hotList().then(res => {
					console.log(res.data);
					this.hotlist = res.data.items
				})
				// 获取新品推荐
				latestProducts(1, 50).then(res => {
					console.log(res.data);
					this.newlist = res.data.rows
				})
				//获取乐居的商品
				lejuLatestProducts().then(res => {
					console.log(res.data.productList);
					this.lejuNewlist = res.data.productList
				})
			}
		},
		onLoad() {
			this.init()
		},
		onShow() {

		}
	}
</script>


<style lang="scss" scoped>
	.home {

		// 轮播
		.swiper {
			width: 750rpx;
			height: 516rpx;
			border-radius: 0 0 60rpx 60rpx;
			box-sizing: border-box;
			overflow: hidden;

			.bannerimage {
				width: 750rpx;
				height: 516rpx;
				box-sizing: border-box;
				border-radius: 0;
			}
		}

		// 轮播下面的分类
		.sort {
			width: 710rpx;
			border-radius: 12rpx;
			padding: 40rpx 40rpx;
			display: flex;
			justify-content: space-between;
			box-sizing: border-box;
			background-color: #fff;
			margin: 40rpx auto;

			.item {
				width: 100rpx;
				box-sizing: border-box;

				image {
					width: 100rpx;
					height: 100rpx;
					border-radius: 20rpx;
					box-sizing: border-box;
				}

				.text {
					width: 100rpx;
					text-align: center;
					box-sizing: border-box;
					font-size: 28rpx;
					color: #666;
				}

			}
		}

		// 通知区域
		.notice {
			width: 710rpx;
			height: 100rpx;
			margin: 0 auto;
			padding: 0rpx 40rpx;
			background-color: #FFFFFF;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			line-height: 100rpx;

			.notice-left {
				height: 100rpx;
				width: 220rpx;
				display: flex;
				box-sizing: border-box;
				justify-content: space-between;
				font-size: 24rpx;

				image {
					width: 48rpx;
					height: 48rpx;
					margin-top: 26rpx;
					box-sizing: border-box;
				}

				.text {
					color: orange;
					margin-right: 30rpx;
					box-sizing: border-box;
				}
			}

			.swiper {
				width: 460rpx;
				height: 100rpx;
				box-sizing: border-box;
				border-radius: 0;

				.item {
					display: flex;
					justify-content: space-between;
					box-sizing: border-box;

					.goodsname {
						width: 250rpx;
						font-size: 24rpx;
						box-sizing: border-box;
						text-indent: 20rpx;
					}

					.goodsprice {
						padding: 20rpx;
						width: 210rpx;
						font-size: 24rpx;
						box-sizing: border-box;
						text-align: center;
						line-height: 30rpx;
						color: red;

						.oldprice {
							color: #333;
							text-decoration: line-through;
							box-sizing: border-box;
						}
					}
				}

			}
		}

		// 热门推荐标题
		.area-title {
			padding: 40rpx 0;
			font-size: 32rpx;
			text-indent: 40rpx;
			box-sizing: border-box;
			font-weight: 600;
		}

		// 热门推荐区域
		.swiper-hot {
			height: 310rpx;
			background-color: #fff;
			padding: 40rpx 0rpx;
			width: 710rpx;
			box-sizing: border-box;
			margin: 0 auto;
			border-radius: 12rpx;

			.item {
				width: 208rpx;
				height: 200rpx;
				box-sizing: border-box;

				image {
					width: 208rpx;
					height: 176rpx;
					border-radius: 12rpx;
					box-sizing: border-box;
				}

				.name {
					width: 208rpx;
					text-align: left;
					font-size: 24rpx;
					margin-top: 10rpx;
					overflow: hidden;
					box-sizing: border-box;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}
		}

		// 新品推荐
		.newgoods {
			display: flex;
			overflow: auto;
			box-sizing: border-box;
			justify-content: space-between;

			.item {
				border-radius: 12rpx;
				width: 580rpx;
				height: 240rpx;
				padding: 40rpx;
				margin-left: 40rpx;
				box-sizing: border-box;
				box-shadow: 0 8rpx 28rpx 0 rgba(122, 98, 75, 0.12);
				background-color: #fff;
				display: flex;
				justify-content: space-between;

				image {
					width: 200rpx;
					height: 160rpx;
					box-sizing: border-box;
					border-radius: 12rpx;
				}

				.goodsinfo {
					margin-left: 30rpx;
					width: 250rpx;
					box-sizing: border-box;
					height: 160rpx;
					padding: 20rpx 0;
					font-size: 24rpx;

					.name {
						width: 260rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						box-sizing: border-box;
						white-space: nowrap;
					}

					.price {
						margin-top: 40rpx;
						box-sizing: border-box;
					}
				}
			}
		}

		//猜你喜欢
		.like {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
			width: 670rpx;
			margin: 0 auto;
			box-sizing: border-box;

			.item {
				box-shadow: 0 8rpx 28rpx 0 rgba(122, 98, 75, .12);
				border-radius: 12rpx;
				overflow: hidden;
				background-color: #FFFFFF;
				box-sizing: border-box;
				width: 320rpx;
				height: 420rpx;
				margin-bottom: 40rpx;

				image {
					box-sizing: border-box;
					width: 320rpx;
					height: 240rpx;
				}

				.title {
					font-size: 26rpx;
					padding: 0 20rpx;
					overflow: hidden;
					box-sizing: border-box;
					text-overflow: ellipsis;
					white-space: nowrap;
					margin-top: 20rpx;
				}

				.brandprice {
					margin-top: 40rpx;
					padding: 0 20rpx;
					display: flex;
					justify-content: space-between;
					box-sizing: border-box;
					font-size: 24rpx;
				}
			}
		}

	}
</style>
